package org.idea.test;

import com.google.gson.Gson;
import org.idea.entity.Bank;

import java.util.ArrayList;
import java.util.List;

/**
 * Gson 工具类的简单使用
 *
 * @Author zqx
 * @Date 2023-10-25
 */
public class MainTestGson02 {
    public static void main(String[] args) {
        Bank bank1 = new Bank(1001,"张三",100) ;
        Bank bank2 = new Bank(1002,"李四",300) ;
        Bank bank3 = new Bank(1003,"王五",400) ;

        List<Bank> list = new ArrayList<>();
        list.add(bank1);
        list.add(bank2);
        list.add(bank3);


        // 把 bank 对象序列为一个 JSON 字符串 - [{customerId:10086,customerName:'中国移动-吸血鬼',currentMoney:100},{customerId:10086,customerName:'中国移动-吸血鬼',currentMoney:100},{customerId:10086,customerName:'中国移动-吸血鬼',currentMoney:100}]

        String json = new Gson().toJson(list);

        System.out.println(json);


    }
}
